package com.zcc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {
    @GetMapping("t1")
    //用注解的方式显示定义某个参数需要从前端接受数据，进行绑定，而且必须从前端获取，否则报错
    public String test1(@RequestParam("username") String name, Model model) {
        //接受前端参数
        System.out.println("接受的前端参数为:"+name);
        //将处理结果传递给前端
        model.addAttribute("msg",name);
        //视图跳转
        return "hello";
    }

    @GetMapping("t2")
    public String test2(Model model) {
        model.addAttribute("msg","hello");
        return "hello";
    }
}
